<script>
export default {
    name: "Login",
    methods:{
        async loginHandler(){
            const adminName = this.$refs.adminName.value.trim();
            const password = this.$refs.password.value.trim();
            if(adminName.length>0 && password.length>0){
                // dispatch来调用action函数
                // dispatch返回的是一个Promise实例，实例的成功值为action函数的返回值
                await this.$store.dispatch("admin/login",{
                    adminName,
                    password
                });
                // console.log("result",result);
                if(this.$route.query.returnUrl){
                    this.$router.push(this.$route.query.returnUrl);
                }else this.$router.push("/my");

            }else{
                alert("请输入账号或密码！")
            }
        }
    }
}
</script>

<template>
<form>
    <p>管理员账号：<input ref="adminName" type="text"></p>
    <p>管理员密码：<input ref="password" type="password"></p>
    <button @click.prevent="loginHandler">登陆</button>
</form>
</template>

<style scoped>

</style>